from time import sleep

from selenium.webdriver.common.by import By

from service.login import Login
from util.Util import BoxDriver,BasePage

class Adddocument(BasePage):

    def dingwei(self):
        self.driver.click(By.XPATH, '//*[@id="s-menu-superadmin"]/button')
        self.driver.switch_to_frame_index(0)

    def adddocument(self,):
        # 添加成员
        self.driver.click(By.LINK_TEXT, '添加成员')

        self.driver.click(By.LINK_TEXT, "维护部门")
        sleep(2)
        self.driver.input(By.NAME, "children[1]","测试部门")
        self.driver.input(By.NAME, "children[2]","测试部门1")
        self.driver.input(By.NAME, "children[3]","测试部门2")
        self.driver.input(By.NAME, "children[4]","测试部门3")
        self.driver.input(By.NAME, "children[5]","测试部门4")
        self.driver.click(By.ID, "submit")
        # bug 如果之间就报错就嗝屁
        try:
            while True:
                sleep(2)
                self.driver.click(By.LINK_TEXT, "删除")
                self.driver.alert_accept()
        except Exception as e:
            print("删除结束")

if __name__ == '__main__':
    driver = BoxDriver('Chrome')
    Login(driver).login('admin', '123456')
    adddocument = Adddocument(driver)
    adddocument.dingwei()
    adddocument.adddocument()
